
import java.io.BufferedInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.print.DocFlavor;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Admin
 */
public class Receive implements Runnable {

    private byte[] buff;
    private DatagramSocket socket;
    private DatagramPacket pks=null;
    private File fi;

    public Receive(DatagramSocket socket) throws IOException {
        this.socket = socket;
        buff = new byte[1024];
        this.pks = new DatagramPacket(this.buff, buff.length);
    }
    public Receive(DatagramPacket packet,String sendBuff) throws IOException {
        this.pks=packet;
        this.buff=sendBuff.getBytes();
    }
    private File processData(DatagramPacket pk) throws IOException, Exception {
          System.out.println(new String(pk.getData()));
          //Send s=new Send(socket, pk,"1");
          //Thread t=new Thread(s);
          //t.start();
//        DataInputStream dis=new DataInputStream(System.in);
//        String s=dis.readLine();
//        
//        File fi=new File(s);
//        FileOutputStream fos=new FileOutputStream(fi);
//        fos.write(data);
//        fos.close();
        return fi;
    }

    @Override
    public void run() {
        try {
            System.out.println("Client da nhan"+new String(pks.getData()));
        } catch (Exception ex) {
            Logger.getLogger(Receive.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    /**
     * @return the pks
     */
    public DatagramPacket getPks() {
        return pks;
    }

    /**
     * @param pks the pks to set
     */
    public void setPks(DatagramPacket pks) {
        this.pks = pks;
    }

    /**
     * @return the fi
     */
    public File getFi() {
        return fi;
    }

    /**
     * @param fi the fi to set
     */
    public void setFi(File fi) {
        this.fi = fi;
    }
}
